package com.xiaozhi.config;


import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MilvusConfig {

    @Value("${milvus.host:localhost}")
    private String host;

    @Value("${milvus.port:19530}")
    private Integer port;

    @Value("${milvus.database:default}")
    private String databaseName;

    @Value("${milvus.timeout:15000}")
    private long timeoutMs;


    @Value("${milvus.username:root}")
    private String username;

    @Value("${milvus.password:milvus}")
    private String password;

    @Bean
    public MilvusClientV2 milvusClient() {
        System.out.println("Creating Milvus v2 client with host: " + host + ", port: " + port + ", database: " + databaseName);

        String uri = "http://" + host + ":" + port;

        ConnectConfig config = ConnectConfig.builder()
                .uri(uri)
                .username(username)
                .password(password)
                .dbName(databaseName)
                .connectTimeoutMs(timeoutMs)
                .build();

        MilvusClientV2 client = new MilvusClientV2(config);
        System.out.println("Milvus v2 client created successfully.=====================================");
        return client;
    }
}